<?php

namespace Wilead\UserManagerBundle\EventListener;

use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface,
    Symfony\Component\HttpFoundation\Request,
    Symfony\Component\Security\Core\Authentication\Token\TokenInterface,
    Symfony\Component\Routing\Router,
    Symfony\Component\Security\Core\SecurityContext,
    Symfony\Component\HttpFoundation\RedirectResponse;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of LoginSuccessHanler
 *
 * @author jack
 */
class LoginSuccessHanler implements AuthenticationSuccessHandlerInterface {

    private $router;
    private $security;

    public function __construct(Router $router, SecurityContext $security) {
        $this->router = $router;
        $this->security = $security;
    }

    public function onAuthenticationSuccess(Request $request, TokenInterface $token) {
        if ($this->security->isGranted('ROLE_ADMIN')) {
            return new RedirectResponse($this->router->generate('manager_default'));
        } else {
            return new RedirectResponse($this->router->generate('messagelog'));
        }
    }

}

?>
